<?php

class Application_Form_Subscribe extends Zend_Form
{

    public function init()
    {
        // Set the method for the display form to POST
        $this->setMethod('post');
 
        // Add a text element
        $this->addElement('text', 'name', array(
            'label'      => 'Your name:',
            'required'   => true,
            'filters'    => array('StringTrim')
        ));
        
        // Add a text element
        $this->addElement('text', 'firstname', array(
            'label'      => 'Your firstname:',
            'required'   => true,
            'filters'    => array('StringTrim')
        ));
        
        // Add an email element
        $this->addElement('text', 'email', array(
            'label'      => 'Your email:',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array('EmailAddress')
        ));
        
        // Add a text element
        $this->addElement('text', 'login', array(
            'label'      => 'Choose a login:',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('validator' => 'StringLength', 'options' => array(6, 20))
                )
        ));
        $this->getElement('login')->setAttrib("onchange", "checkLogin()");
        $this->getElement('login')->getValidator('StringLength')->setMessage('Your login must be composed of x caracters with x between 6 and 20');
 
        // Add a password element
        $this->addElement('password', 'password', array(
            'label'      => 'Choose a password:',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('validator' => 'StringLength', 'options' => array(6, 20))
                )
        ));
 
        // Add a password element
        $this->addElement('password', 'password_again', array(
            'label'      => 'Confirm your password:',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('validator' => 'StringLength', 'options' => array(6, 20)), array('identical', true, array('password') )
                )
        ));
 
        // Add a captcha
        $this->addElement('captcha', 'captcha', array(
            'label'      => 'Please enter the 5 letters displayed below:',
            'required'   => true,
            'captcha'    => array(
                'captcha' => 'Figlet',
                'wordLen' => 5,
                'timeout' => 300
            )
        ));
        
        // Add the submit button
        $this->addElement('submit', 'submit', array(
            'ignore'   => true,
            'label'    => 'Subscribe',
        ));
 
        // And finally add some CSRF protection
        $this->addElement('hash', 'csrf', array(
            'ignore' => true,
        ));
    
    }


}

